package com.cx330;

public class Example10 {
    public static void main(String[] args) {
        System.out.println(9 & 5); // 结果是1
        /*
        9的二进制：00000000 00000000 00000000 00001001
        5的二进制：00000000 00000000 00000000 00000101
        9 & 5的： 00000000 00000000 00000000 00000001（十进制1）
         */
        int x1 = 1, y1 = 1;
        System.out.println(x1++ == 2 & ++y1 == 2); // false & true结果是false
        // 取x1的1，x1自增为2， 1 == 2 false，y1自增为2，取y1的值2，2 == 2 true
        System.out.println("x1 = " + x1 + ", y1 = " + y1); // x1 = 2, y1 = 2
        System.out.println(++x1 == 2 && ++ y1 == 2); // 结果为false
        // x1自增为3，取x1的3，3 == 2 false，短路
        System.out.println("x1 = " + x1 + ", y1 = " + y1); // x1 = 3, y1 = 2

        System.out.println(9 | 5); // 结果是13
        /*
        9的二进制：00000000 00000000 00000000 00001001
        5的二进制：00000000 00000000 00000000 00000101
        9 | 5的： 00000000 00000000 00000000 00001101（十进制13）
         */
        int x2 = 1, y2 = 1;
        System.out.println(x2++ == 1 | ++y2 == 1); // true | false结果是true
        // 取x2的1，x2自增为2，1 == 1 true，y2自增为2，取y2的值2，2 == 1 false
        System.out.println("x2 = " + x2 + ", y2 = " + y2); // x2 = 2, y2 = 2
        System.out.println(x2++ == 2 || ++y2 == 2); // true
        // 取x2的2，x2自增为3，2 == 2 true，短路
        System.out.println("x2 = " + x2 + ", y2 = " + y2); // x2 = 3, y2 = 2
    }
}
